Useful model instance properties and methods
Contents
11. Useful model instance properties and methods¶
The focus of this chapter is to introduce some properties and methods of the model instance.
First a model and data is loaded, then a scenario is run. Then we have some content to use.
A model instance gives the user access to a number of properties and methods which helps in managing the model and its results.
If ´´´mmodel´´ is a model instance mmodel.<property> will return a property. Some properties can also be assigned by the user just by:
mmodel.property = something
The model class itself also have a few properties.
11.1. Import the model class¶
This class incorporates most of the methods used to manage a model.
Assuming the ModelFlow library has been installed on your machine, the following imports set up your notebook so that you can run the cells in this notebook.
In order to manipulate plots later matplotlib.pyplot is also imported.
from modelclass import model
import matplotlib.pyplot as plt #
11.2. Class methods to help in Jupyter Notebook¶
11.2.1. .widescreen() use Jupyter Notebook in widescreen¶
Enables the whole viewing area of the browser.
model.widescreen()
11.3. .modelload Load a pre-cooked model, data and descriptions¶
In this notebook, we will be using a pre-existing model of Pakistan.
The file ‘pak.pcim’ has been created from a Eviews workspace. It contains all that is needed to run the model:
Model equations
Data
Simulation options
Variable descriptions
Using the ‘modelload’ method of the ‘model’ class, a model instance ‘mpak’ and a ‘result’ DataFrame is created.
mpak,baseline = model.modelload('../models/pak.pcim',run=1,silent=1,keep='Baseline')
mpak
The modelload method processes the file and initiates the model, that we call ‘mpak’ (m for model and pak for Pakistan) with both equations and the data.
‘mpak’ is an instance of the model object with which we will work.
baseline
‘result’ is a Pandas dataframe containing the data that was loaded.
run=1 the model is simulated. The simulation timeframe and options from the time the file where dumped will be used.
The two objects mpak.basedf and mpak.lastdf will contain the simulation result. If run=0 the model will not be simulated.
silent=1 if silent is set to 0 information regarding the simulation will be displayed.
keep=’Baseline’ This saves the result in a dictionary mpak.keep_solutions.
11.4. Create a scenario¶
Many objects relates to comparison of different scenarios. So a scenario is created by updating some exogenous variables.
In this case the carbon tax rates for gas, oil and coal are all set to 29 from 2023 to 2100.
Then the scenario is simulated.
Now the mpak object contains a number of useful properties and methods.
You can find more on this experiment here
scenario_exo = baseline.upd("<2020 2100> PAKGGREVCO2CER PAKGGREVCO2GER PAKGGREVCO2OER = 29")
11.5. () Simulate on a dataframe¶
When calling the model instance like mpak(dataframe,start, end) the model will be simulated for the time frame start to end using the dataframe.
Just above we created a dataframe scenario_exo where the tax variables are updated. Now the mpak can be simulated. We simulate from 2020 to 2100.
scenario = mpak(scenario_exo,2020,2100,keep=f'Coal, Oil and Gastax : 29') # runs the simulation
11.6. Access results¶
Now we have two dataframes with results baseline and scenario. These dataframes can be manipulated and visualized
with the tools provided by the pandas library and other like Matplotlib and Plotly. However to make things easy the first and
latest simulation result is also in the mpak object:
mpak.basedf: Dataframe with the values for baseline
mpak.lastdf: Dataframe with the values for alternative
This means that .basedf and .lastdf will contain the same result after the first simulation.
If new scenarios are simulated the data in .lastdf will then be replaced with the latest results.
These dataframes are used by a number of model instance methods as you will see later.
The user can assign dataframes to both .basedf and .lastdf. This is useful for comparing simulations which are not the first and last.
print(f'mpak.basedf: Dataframe: with {mpak.basedf.shape[0]} years and {mpak.basedf.shape[1]} variables')
print(f'mpak.lastdf: Dataframe: with {mpak.lastdf.shape[0]} years and {mpak.lastdf.shape[1]} variables')
mpak.basedf: Dataframe: with 121 years and 1291 variables
mpak.lastdf: Dataframe: with 121 years and 1291 variables
11.6.1. .keep_solutions, A dictionary of dataframes with results¶
Create a dictionary of dataframes with .keep_solutions. Sometimes we want to be able to compare more than two scenarios. Using keep='some description' the dataframe with results can be saved into a dictionary with the description as key and the dataframe as value.
In our example we have created two scenarios. A baseline and a scenario with the tax set to 29. So mpak.keep_solutions looks like this:
print('mpak.keep_solutions contains:')
for key,value in mpak.keep_solutions.items():
print(f'key = {key:25}|Dataframe: {value.shape[0]} years and {value.shape[1]} variables')
mpak.keep_solutions contains:
key = Baseline |Dataframe: 121 years and 1291 variables
key = Coal, Oil and Gastax : 29|Dataframe: 121 years and 1291 variables
Sometime it can be useful to reset the keep_solutions so that new solutions can be inspected. This is done by replacing it with an empty dictionary. Two methods can be used:
mpak.keep_solutions = {}
or in the simulation call:
mpak(,,keep=’’)
11.6.2. More on manipulating keep_solution here: ¶
11.6.3. .oldkwargs, Options in the simulation call is persistent between calls¶
When simulating a model the parameters are persistent. So the user just have to provide the solution options once. These persistent parameters are located in the property .oldkwargs.
The user may have to reset the parameters, this is done like this:
To reset the options just do:
mpak.oldkwargs = {}
In this case the persistent parameters are:
mpak.oldkwargs
{'silent': 1, 'keep': 'Coal, Oil and Gastax : 29'}
11.7. .current_per, The time frame operations are performed on¶
Most operations on a model class instance operates on the current time frame. It is a subset of the row index of the dataframe which is simulated.
In this case it is:
mpak.current_per
Int64Index([2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030,
2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041,
2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052,
2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063,
2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074,
2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085,
2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096,
2097, 2098, 2099, 2100],
dtype='int64')
scenario.index # the index of the dataframe
Int64Index([1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,
...
2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100],
dtype='int64', length=121)
11.7.1. .smpl, Set time frame¶
The time frame can be set like this
mpak.smpl(2020,2025)
mpak.current_per
Int64Index([2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
11.7.2. .set_smpl, Set timeframe for a local scope¶
For many operations it can be useful to apply the operations for a shorter time frame, but retain the global time frame after the operation.
This can be done with a with statement like this.
You will see this used here
print(f'Global time before {mpak.current_per}')
with mpak.set_smpl(2022,2023):
print(f'Local time frame {mpak.current_per}')
print(f'Unchanged global time {mpak.current_per}')
Global time before Int64Index([2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
Local time frame Int64Index([2022, 2023], dtype='int64')
Unchanged global time Int64Index([2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
11.7.3. .set_smpl_relative Set relative timeframe for a local scope¶
When creating a script it can be useful to set the time frame relative to the current time.
Like this:
print(f'Global time before {mpak.current_per}')
with mpak.set_smpl_relative (-1,0):
print(f'Local time frame {mpak.current_per}')
print(f'Unchanged global time {mpak.current_per}')
Global time before Int64Index([2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
Local time frame Int64Index([2019, 2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
Unchanged global time Int64Index([2020, 2021, 2022, 2023, 2024, 2025], dtype='int64')
11.8. Using the index operator to [ ] to select and visualize variables.¶
The index operator [ ] can be used to select variables and then process the values for quick analysis.
To select variables the method accept pattern which defines variable names. Wildcards:
\*matches everything?matches any single character\[seq]matches any character in seq\[!seq]matches any character not in seq
For more on wildcards can be used, the specification can be found here https://docs.python.org/3/library/fnmatch.html
In the following example we are selecting the results of mpak[‘PAKNYGDPMKTPKN’]
This call will return a special class (called vis). It implements a number
of methods and properties which comes in handy for quick analyses.
Then several properties and methods are chained with the following plot as a result:
with mpak.set_smpl(2020,2100):
mpak['PAKNYGDPMKTPKN'].difpctlevel.mul100.rename().plot(colrow=1,
title='Difference to baseline in percent',top=0.8);
But first some basic information
11.8.1. model[‘#ENDO’]¶
Use ‘#ENDO’ to access all endogenous variables in your model instance.
For the sake of space, the result is saved in the variable ‘allendo’ and not printed.
allendo = mpak['#ENDO']
# allendo.show
11.8.2. Access values in .lastdf and .basedf¶
To limit the output printed, we set the time frame to 2020 to 2023.
mpak.smpl(2020,2023);
To access the values of ‘PAKNYGDPMKTPKN’ and ‘PAKNECONPRVTKN’ from the latest simulation: this is correct, right?
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN']
To access the values of ‘PAKNYGDPMKTPKN’ and ‘PAKNECONPRVTKN’ from the base dataframe, specify .base
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].base
11.8.3. .df Pandas dataframe¶
If you need the data to calculate on use the .df
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].df
| PAKNYGDPMKTPKN | PAKNECONPRVTKN | |
|---|---|---|
| 2020 | 2.648318e+07 | 2.268967e+07 |
| 2021 | 2.723559e+07 | 2.331771e+07 |
| 2022 | 2.796332e+07 | 2.394832e+07 |
| 2023 | 2.869072e+07 | 2.455519e+07 |
11.8.4. .show as a html table with tooltips¶
If you want the variable descriptions use this
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].show
11.8.5. .names Variable names¶
If you select variables using wildcards, then you can access the names that correspond to your query.
mpak['PAKNYGDP??????'].names
['PAKNYGDPDISCCN',
'PAKNYGDPDISCKN',
'PAKNYGDPFCSTCN',
'PAKNYGDPFCSTKN',
'PAKNYGDPFCSTXN',
'PAKNYGDPMKTPCD',
'PAKNYGDPMKTPCN',
'PAKNYGDPMKTPKD',
'PAKNYGDPMKTPKN',
'PAKNYGDPMKTPXN',
'PAKNYGDPPOTLKN']
11.8.6. .frml The formulas¶
Use .frml to access all the equations for the endogenous variables.
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].frml
PAKNYGDPMKTPKN : FRML <> PAKNYGDPMKTPKN = PAKNECONPRVTKN+PAKNECONGOVTKN+PAKNEGDIFTOTKN+PAKNEGDISTKBKN+PAKNEEXPGNFSKN-PAKNEIMPGNFSKN+PAKNYGDPDISCKN+PAKADAP*PAKDISPREPKN $
PAKNECONPRVTKN : FRML <Z,EXO> PAKNECONPRVTKN = (PAKNECONPRVTKN(-1)*EXP(-PAKNECONPRVTKN_A+ (-0.2*(LOG(PAKNECONPRVTKN(-1))-LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1)))+1*((LOG((PAKNYYWBTOTLCN*(1-PAKGGREVDRCTXN/100))/PAKNECONPRVTXN))-(LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1))))+0.0303228629698929+0.0163839011059956*DURING_2010-0.3*(PAKFMLBLPOLYXN/100-((LOG(PAKNECONPRVTXN))-(LOG(PAKNECONPRVTXN(-1)))))) )) * (1-PAKNECONPRVTKN_D)+ PAKNECONPRVTKN_X*PAKNECONPRVTKN_D $
11.8.7. .rename() Rename variables to descriptions¶
Use .rename() to assign variable descriptions as variable names.
Handy when plotting!
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].rename()
11.8.8. Transformations of solution results¶
When the variables has been selected through the index operator a number of standard data transformations can be performed.
Transfomation |
Meaning |
expression |
|---|---|---|
pct |
Growth rates |
\(\left(\cfrac{this_t}{this_{t-1}}-1\right )\) |
dif |
Difference in level |
\(l-b\) |
difpct |
Differens in growth rate |
\(\left( \cfrac{l_t}{l_{t-1}}-1 \right) - \left(\cfrac{b_t}{b_{t-1}}-1 \right)\) |
difpctlevel |
differens in level in pct of baseline |
\(\left( \cfrac{l_t-b_t}{b_{t}} \right) \) |
mul100 |
multiply by 100 |
\(this_t \times 100\) |
\(this\) is the chained value. Default lastdf but if preseeded by .base the values from .basedf will be used
\(b\) is the values from .basedf
\(l\) is the values from .lastdf
11.8.9. .dif Difference in level¶
The ‘dif’ command displays the difference in levels of the latest and previous solutions.
\(l-b\)
where l is the variable from the .lastdf and b is the variable from .basedf.
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].dif
11.8.10. .pct Growthrates¶
Display growth rates
\(\left(\cfrac{l_t}{l_{t-1}}-1\right )\)
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].pct
11.8.11. .difpct property difference in growthrate¶
The difference in the growth rates between the last and base dataframe.
\(\left( \cfrac{l_t}{l_{t-1}}-1 \right) - \left(\cfrac{b_t}{b_{t-1}}-1 \right)\)
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].difpct
11.8.12. .difpctlevel percent difference of levels¶
\(\left( \cfrac{l_t-b_t}{b_{t}} \right) \)
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].difpctlevel
11.8.13. mul100 multiply by 100¶
multiply growth rate by 100.
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].pct.mul100
11.9. .plot chart the selected and transformed variables¶
After the varaibles has been selected and transformed, they can be plotted. The .plot() method plots the selected variables separately
mpak.smpl(2020,2100);
mpak['PAKNYGDP??????'].rename().plot();
11.9.1. Options to plot()¶
Common:
title (optional): title. Defaults to ‘’.
colrow (TYPE, optional): columns per row . Defaults to 2.
sharey (TYPE, optional): Share y axis between plots. Defaults to False.
top (TYPE, optional): relative position of the title. Defaults to 0.90.
More excotic:
splitchar (TYPE, optional): if the name should be split . Defaults to ‘__’.
savefig (TYPE, optional): save figure. Defaults to ‘’.
xsize (TYPE, optional): x size default to 10
ysize (TYPE, optional): y size per row, defaults to 2
ppos (optional): # of position to use if split. Defaults to -1.
kind (TYPE, optional): matplotlib kind . Defaults to ‘line’.
mpak['PAKNYGDP??????'].difpct.mul100.rename().plot(title='GDP growth ',top = 0.92);
11.10. Plotting inspiration¶
The following graph shows the components of GDP using the values of the baseline dataframe.
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN PAKNEGDIFTOTKN'].\
difpctlevel.mul100.rename().\
plot(title='Components of GDP in pct of baseline',colrow=1,top=0.90,kind='bar') ;
11.10.1. Heatmaps¶
For some model types heatmaps can be helpful, and they come out of the box. This feature was developed for use by bank stress test models.
with mpak.set_smpl(2020,2030):
heatmap = mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].pct.rename().mul100.heat(title='Growth rates',annot=True,dec=1,size=(10,3))
11.10.2. Violin, swarm and boxplots,¶
Not obvious for macro models, but useful for stress test models with many banks.
with mpak.set_smpl(2020,2030):
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].difpct.box()
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].difpct.violin()
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].difpct.swarm()
11.10.3. Plot baseline vs alternative¶
A raw routine, only showing levels. To make it really useful it should be expanded.
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].plot_alt() ;
ORIGINAL
11.11. Relationships (dependencies) between variables¶
ModelFlow perform a number of analytical chores, that it can oresent graphically or in tabular form.
These inlude presenting the relationships between variables. In this case, we are displaying all of the vairables that depend directly upon GDP and consumption and those that are determined by them. Directly because in this example we are only going one step up and backward inthe formulae.
The thicker arrow the more dependent the variable is on the other, ie, it is related to the cobntribution that the variable made to the value of the other.
11.12. .draw() Graphical presentation of relationships between variables¶
.draw() helps you understand the relationship between variables in your model better.
The thicker the arrow the more dependent the variable is on the other.
11.12.1. .draw(up = level, down = level)¶
You can specify how many levels up and down you want in your graphical presentation (Needs more explanation).
In this example all variables that depend directly upon GDP and consumption as well as those that are determined by them, are displayed. This means one step and one backwards (more explanation).
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].draw(up=1,down=1) # diagram of all direct dependencies
11.12.2. .draw(filter = minimal_impact)¶
Use filter to only include variables that impact or are impacted by for example 20%
mpak['PAKNECONPRVTKN'].draw(up=3,down=1,filter=20)
11.13. dekomp() Contribution of variables to observed change¶
The dekomp command decomposes the contributions of the right hand side variables to the observed change in the left hand side variables.
In the example below, from our simulation imposing a carbon tax, the change in consumption demand had a large impact on GDP. 280% of the total in 2023 (third set of results), while government consumption contributed 24% and investment 16%.
Imports had a strong negative contribution of -227% since much of the increase in consumption, investment and government demand was imported.
with mpak.set_smpl(2021,2025):
mpak['PAKNYGDPMKTPKN PAKNECONPRVTKN'].dekomp() # frml attribution
Formula : FRML <> PAKNYGDPMKTPKN = PAKNECONPRVTKN+PAKNECONGOVTKN+PAKNEGDIFTOTKN+PAKNEGDISTKBKN+PAKNEEXPGNFSKN-PAKNEIMPGNFSKN+PAKNYGDPDISCKN+PAKADAP*PAKDISPREPKN $
2021 2022 2023 2024 2025
Variable lag
Base 0 27202580.708360 27801259.416024 28499818.713903 29256735.735593 30047560.475207
Alternative 0 27235594.312527 27963320.775578 28690715.630996 29445700.399677 30238498.358997
Difference 0 33013.604167 162061.359555 190896.917093 188964.664084 190937.883791
Percent 0 0.121362 0.582928 0.669818 0.645884 0.635452
Contributions to differende for PAKNYGDPMKTPKN
2021 2022 2023 2024 2025
Variable lag
PAKNECONPRVTKN 0 -514010.790676 -445733.081021 -457677.084042 -485936.695182 -495257.269800
PAKNECONGOVTKN 0 275618.462539 268128.632065 252327.213892 239826.746128 231710.108381
PAKNEGDIFTOTKN 0 120796.109779 143323.042999 155599.315502 163987.298120 171159.408432
PAKNEGDISTKBKN 0 -0.067555 -0.069308 0.032096 0.153108 0.141474
PAKNEEXPGNFSKN 0 104.352192 -30.004653 -668.457927 -1711.573450 -3035.355902
PAKNEIMPGNFSKN 0 150505.212786 196372.522131 241316.053376 272799.582818 286361.677009
PAKNYGDPDISCKN 0 -0.067555 -0.069308 0.032096 0.153108 0.141474
PAKADAP 0 -0.067555 -0.069308 0.032096 0.153108 0.141474
PAKDISPREPKN 0 -0.067555 -0.069308 0.032096 0.153108 0.141474
Share of contributions to differende for PAKNYGDPMKTPKN
2021 2022 2023 2024 2025
Variable lag
PAKNEIMPGNFSKN 0 456% 121% 126% 144% 150%
PAKNECONGOVTKN 0 835% 165% 132% 127% 121%
PAKNEGDIFTOTKN 0 366% 88% 82% 87% 90%
PAKNEGDISTKBKN 0 -0% -0% 0% 0% 0%
PAKNYGDPDISCKN 0 -0% -0% 0% 0% 0%
PAKADAP 0 -0% -0% 0% 0% 0%
PAKDISPREPKN 0 -0% -0% 0% 0% 0%
PAKNEEXPGNFSKN 0 0% -0% -0% -1% -2%
PAKNECONPRVTKN 0 -1557% -275% -240% -257% -259%
Total 0 100% 100% 100% 100% 100%
Residual 0 -0% -0% 0% 0% 0%
Contribution to growth rate PAKNYGDPMKTPKN
2021 2022 2023 2024 2025
Variable lag
PAKNECONPRVTKN 0 -0.0% -0.0% -0.0% -0.0% -0.0%
PAKNECONGOVTKN 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNEGDIFTOTKN 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNEGDISTKBKN 0 -0.0% -0.0% 0.0% 0.0% 0.0%
PAKNEEXPGNFSKN 0 0.0% -0.0% -0.0% -0.0% -0.0%
PAKNEIMPGNFSKN 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNYGDPDISCKN 0 -0.0% -0.0% 0.0% 0.0% 0.0%
PAKADAP 0 -0.0% -0.0% 0.0% 0.0% 0.0%
PAKDISPREPKN 0 -0.0% -0.0% 0.0% 0.0% 0.0%
Formula : FRML <Z,EXO> PAKNECONPRVTKN = (PAKNECONPRVTKN(-1)*EXP(-PAKNECONPRVTKN_A+ (-0.2*(LOG(PAKNECONPRVTKN(-1))-LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1)))+1*((LOG((PAKNYYWBTOTLCN*(1-PAKGGREVDRCTXN/100))/PAKNECONPRVTXN))-(LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1))))+0.0303228629698929+0.0163839011059956*DURING_2010-0.3*(PAKFMLBLPOLYXN/100-((LOG(PAKNECONPRVTXN))-(LOG(PAKNECONPRVTXN(-1)))))) )) * (1-PAKNECONPRVTKN_D)+ PAKNECONPRVTKN_X*PAKNECONPRVTKN_D $
2021 2022 2023 2024 2025
Variable lag
Base 0 23831715.834234 24394056.968682 25012863.134716 25644576.437267 26265982.972636
Alternative 0 23317705.111113 23948323.956969 24555186.018577 25158639.588977 25770725.561362
Difference 0 -514010.723121 -445733.011713 -457677.116139 -485936.848290 -495257.411274
Percent 0 -2.156835 -1.827220 -1.829767 -1.894891 -1.885547
Contributions to differende for PAKNECONPRVTKN
2021 2022 2023 2024 2025
Variable lag
PAKNECONPRVTKN -1 -519278.985439 -421406.700888 -364946.988812 -374445.720069 -397444.132770
PAKNECONPRVTKN_A 0 0.000000 0.000000 0.000000 0.000000 0.000000
PAKNYYWBTOTLCN -1 144221.093731 27963.494176 -67399.351041 -105242.269211 -127427.362591
PAKGGREVDRCTXN -1 0.000000 0.000000 0.000000 0.000000 0.000000
PAKNECONPRVTXN -1 313813.157454 295937.664188 302656.152915 319638.278653 337038.934513
PAKNYYWBTOTLCN 0 -34078.696592 81914.064162 127795.901156 154640.608408 194233.141442
PAKGGREVDRCTXN 0 0.000000 0.000000 0.000000 0.000000 0.000000
PAKNECONPRVTXN 0 -409469.763597 -419445.488433 -443516.071433 -467985.528092 -489904.289367
DURING_2010 0 0.000000 0.000000 0.000000 0.000000 0.000000
PAKFMLBLPOLYXN 0 -15494.113694 -15900.075339 -17009.587153 -17718.206073 -17966.201327
PAKNECONPRVTKN_D 0 0.000000 0.000000 0.000000 0.000000 0.000000
PAKNECONPRVTKN_X 0 0.000000 0.000000 0.000000 0.000000 0.000000
Share of contributions to differende for PAKNECONPRVTKN
2021 2022 2023 2024 2025
Variable lag
PAKNECONPRVTXN 0 80% 94% 97% 96% 99%
PAKNECONPRVTKN -1 101% 95% 80% 77% 80%
PAKNYYWBTOTLCN -1 -28% -6% 15% 22% 26%
PAKFMLBLPOLYXN 0 3% 4% 4% 4% 4%
PAKNECONPRVTKN_A 0 -0% -0% -0% -0% -0%
PAKGGREVDRCTXN -1 -0% -0% -0% -0% -0%
0 -0% -0% -0% -0% -0%
DURING_2010 0 -0% -0% -0% -0% -0%
PAKNECONPRVTKN_D 0 -0% -0% -0% -0% -0%
PAKNECONPRVTKN_X 0 -0% -0% -0% -0% -0%
PAKNYYWBTOTLCN 0 7% -18% -28% -32% -39%
PAKNECONPRVTXN -1 -61% -66% -66% -66% -68%
Total 0 101% 101% 101% 101% 101%
Residual 0 1% 1% 1% 1% 1%
Contribution to growth rate PAKNECONPRVTKN
2021 2022 2023 2024 2025
Variable lag
PAKNECONPRVTKN -1 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNECONPRVTKN_A 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNYYWBTOTLCN -1 0.0% 0.0% -0.0% -0.0% -0.0%
PAKGGREVDRCTXN -1 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNECONPRVTXN -1 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNYYWBTOTLCN 0 -0.0% 0.0% 0.0% 0.0% 0.0%
PAKGGREVDRCTXN 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNECONPRVTXN 0 -0.0% -0.0% -0.0% -0.0% -0.0%
DURING_2010 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKFMLBLPOLYXN 0 -0.0% -0.0% -0.0% -0.0% -0.0%
PAKNECONPRVTKN_D 0 0.0% 0.0% 0.0% 0.0% 0.0%
PAKNECONPRVTKN_X 0 0.0% 0.0% 0.0% 0.0% 0.0%
11.14. Bespoken plots using matplotlib (or plotly -later) (should go to a separate plot book¶
The predefined plots are not necessary created for presentation purpose. To create bespoken the the plots can be constructed directly in python scripts. The two main libraries are matplotlib and plotly.
11.15. a simple matplotlib plot¶
# first we call our baseline df for 'base' and the last dataframe for alt (which means everything in Danish)
base = mpak.basedf
alt = mpak.lastdf
# The plot
plt.plot(mpak.basedf.loc[2000:2099,'PAKGGBALOVRLCN']/mpak.basedf.loc[2000:2099,'PAKNYGDPMKTPCN']*100,label='Baseline')
plt.plot(mpak.lastdf.loc[2000:2099,'PAKGGBALOVRLCN_'],label='Carbon Tax scenario')
# Setting the y and x labels, legend and title
# set y label
plt.ylabel('% of GDP')
plt.xlabel('Time')
plt.legend()
plt.title('Overall Fiscal balance')
# display plot
plt.show()
11.16. Plot four separate plots of multiple series in grid¶
figure,axs= plt.subplots(2,2,figsize=(11, 7))
axs[0,0].plot(mpak.basedf.loc[2020:2099,'PAKGGBALOVRLCN_'],label='Baseline')
axs[0,0].plot(mpak.lastdf.loc[2020:2099,'PAKGGBALOVRLCN_'],label='Scenario')
#axs[0,0].legend()
axs[0,1].plot(mpak.basedf.loc[2020:2099,'PAKGGDBTTOTLCN_'],label='Baseline')
axs[0,1].plot(mpak.lastdf.loc[2020:2099,'PAKGGDBTTOTLCN_'],label='Scenario')
axs[1,0].plot(mpak.basedf.loc[2020:2099,'PAKGGREVTOTLCN']/mpak.basedf.loc[2020:2099,'PAKNYGDPMKTPCN']*100,label='Baseline')
axs[1,0].plot(mpak.lastdf.loc[2020:2099,'PAKGGREVTOTLCN']/mpak.lastdf.loc[2020:2099,'PAKNYGDPMKTPCN']*100,label='Scenario')
axs[1,1].plot(mpak.basedf.loc[2020:2099,'PAKGGREVGRNTCN']/mpak.basedf.loc[2020:2099,'PAKNYGDPMKTPCN']*100,label='Baseline')
axs[1,1].plot(mpak.lastdf.loc[2020:2099,'PAKGGREVGRNTCN']/mpak.lastdf.loc[2020:2099,'PAKNYGDPMKTPCN']*100,label='Scenario')
#axs2[4].plot(mpak.lastdf.loc[2000:2099,'PAKGGREVGRNTCN']/mpak.basedf.loc[2000:2099,'PAKNYGDPMKTPCN']*100,label='Scenario')
axs[0,0].title.set_text("Fiscal balance (% of GDP)")
axs[0,1].title.set_text("Gov't Debt (% of GDP)")
axs[1,0].title.set_text("Total revenues (% of GDP)")
axs[1,1].title.set_text("Grant Revenues (% of GDP)")
figure.suptitle("Fiscal outcomes")
plt.figlegend(['Baseline','Scenario'],loc='lower left',ncol=5)
figure.tight_layout(pad=2.3) #Ensures legend does not overlap dates